/*
 * Copyright (c) 2025 [ByteDance Ltd. and/or its affiliates.] and/or its affiliates
 * SPDX-License-Identifier: LGPL v2.1+
*/
#ifndef ANDROID_FFmpegBaseXORIOCryptor_H
#define ANDROID_FFmpegBaseXORIOCryptor_H

#include "FFmpegBaseIOCryptor.h"

// 此版本不会将加密参数写入文件
#define CRYPT_VERSION_1 1

// 此版本会将加密参数写入文件
#define CRYPT_VERSION_2 2

#define CRYPT_VERSION_3 3

class FFmpegBaseXORIOCryptor : public FFmpegBaseIOCryptor {
public:
    TECryptorType getType() const override { return TECryptorType_XOR; }

protected:
    int parseParam(const std::map<std::string, FFAny> *params) override;
    int readPacket(uint8_t *buf, int bufSize) override;
    int writePacket(const uint8_t *buf, int bufSize) override;
protected:
    void encryptParamSha256(uint8_t dst[32]);

protected:
    int64_t m_fileSize = 0;
    int64_t m_maxReadPos = 0;
    uint32_t m_bdveTagSize = 0;
    uint32_t m_step = 0;
    uint32_t m_length = 0;
    uint8_t m_key = 0;
    bool m_shouldDecrypt = true;
};

#endif   // ANDROID_FFmpegBaseXORIOCryptor_H
